#include <math.h>
#include <GL/glut.h>
#include "Projectile.h"
#define M_PI 3.14159265358979323846

Projectile::Projectile()
{
	someX = 0.0f;
	someZ = 0.0f;

	numTiles = 30;
}

Projectile::Projectile(float ang, float x, float z)
{
	angle = ang;
	xTranslation = x;
	zTranslation = z;

	someX = 0.0f;
	someZ = 0.0f;

	numTiles = 30;
}

void Projectile::Shoot()
{
	float adjacent = cos(angle*M_PI/180);
	float opposite = sin(angle*M_PI/180);

	someX += adjacent*0.5f;
	someZ += opposite*0.5f;

	glPushMatrix();
		glTranslatef(xTranslation+someX, 0.5f, zTranslation+someZ);
		glColor3f(0.0f,1.0f,0.0f);
		glutSolidSphere(0.5f, 10, 10);
	glPopMatrix();
}

bool Projectile::BoundaryCollision()
{	
	if(xTranslation+someX >= numTiles ||
	   xTranslation+someX <= 0 ||
	   zTranslation+someZ >= numTiles ||
	   zTranslation+someZ <= 0)
		return true;

	else
		return false;
}

void Projectile::ResetPosition()
{
	someX = 0.0f;
	someZ = 0.0f;
}

void Projectile::Set(float ang, float x, float z)
{
	angle = ang;
	xTranslation = x;
	zTranslation = z;
}

float Projectile::GetXPosition()
{
	return (someX+xTranslation);
}

float Projectile::GetZPosition()
{
	return (someZ+zTranslation);
}